package cn.wolfcode.crm.serivce.impl;

import cn.wolfcode.crm.domain.Dictionary;
import cn.wolfcode.crm.domain.DictionaryDetail;
import cn.wolfcode.crm.mapper.DictionaryDetailMapper;
import cn.wolfcode.crm.mapper.DictionaryMapper;
import cn.wolfcode.crm.serivce.IDictionaryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


@Service
public class DictionaryServiceImpl implements IDictionaryService {
    @Autowired
    private DictionaryMapper mapper;
    @Autowired
    private DictionaryDetailMapper dictionaryDetailMapper;
    @Override
    public void deleteByPrimaryKey(Long id) {
        mapper.deleteByPrimaryKey(id);
        dictionaryDetailMapper.deleteDetailByDictionaryId(id);
    }

    @Override
    public void saveOrUpdate(Dictionary record) {
        if (record.getId() == null) {
            //保存操作
            mapper.insert(record);
        }else {
            mapper.updateByPrimaryKey(record);
        }
    }

    @Override
    public Dictionary selectByPrimaryKey(Long id) {
        return mapper.selectByPrimaryKey(id);
    }


    @Override
    public List<Dictionary> selectAll() {
        return mapper.selectAll();
    }

    @Override
    public List<DictionaryDetail> selectAllDetail(Long dictionaryId) {
        return dictionaryDetailMapper.selectAllDetail(dictionaryId);
    }
}
